home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Chat & Communication
/
Digsby build 37
/
digsby_setup.exe
/
lib
/
multifile.pyo
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2008-10-13
|
4KB
|
162 lines
# Source Generated with Decompyle++
# File: in.pyo (Python 2.5)
__all__ = [
'MultiFile',
'Error']
class Error(Exception):
pass
class MultiFile:
seekable = 0
def __init__(self, fp, seekable = 1):
self.fp = fp
self.stack = []
self.level = 0
self.last = 0
if seekable:
self.seekable = 1
self.start = self.fp.tell()
self.posstack = []
def tell(self):
if self.level > 0:
return self.lastpos
return self.fp.tell() - self.start
def seek(self, pos, whence = 0):
here = self.tell()
if whence:
if whence == 1:
pos = pos + here
elif whence == 2:
if self.level > 0:
pos = pos + self.lastpos
else:
raise Error, "can't use whence=2 yet"
if (not None if pos <= pos else pos <= here or self.level > 0) and pos > self.lastpos:
raise Error, 'bad MultiFile.seek() call'
self.fp.seek(pos + self.start)
self.level = 0
self.last = 0
def readline(self):
if self.level > 0:
return ''
line = self.fp.readline()
if not line:
self.level = len(self.stack)
self.last = self.level > 0
if self.last:
raise Error, 'sudden EOF in MultiFile.readline()'
return ''
if self.is_data(line):
return line
else:
marker = line.rstrip()
for i, sep in enumerate(reversed(self.stack)):
if marker == self.section_divider(sep):
self.last = 0
break
continue
if marker == self.end_marker(sep):
self.last = 1
break
continue
else:
return line
if self.seekable:
self.lastpos = self.tell() - len(line)
self.level = i + 1
if self.level > 1:
raise Error, 'Missing endmarker in MultiFile.readline()'
return ''
def readlines(self):
list = []
while None:
line = self.readline()
if not line:
break
continue
return list
def read(self):
return ''.join(self.readlines())
def next(self):
while self.readline():
pass
if self.level > 1 or self.last:
return 0
self.level = 0
self.last = 0
if self.seekable:
self.start = self.fp.tell()
return 1
def push(self, sep):
if self.level > 0:
raise Error, 'bad MultiFile.push() call'
self.stack.append(sep)
if self.seekable:
self.posstack.append(self.start)
self.start = self.fp.tell()
def pop(self):
if self.stack == []:
raise Error, 'bad MultiFile.pop() call'
if self.level <= 1:
self.last = 0
else:
abslastpos = self.lastpos + self.start
self.level = max(0, self.level - 1)
self.stack.pop()
if self.seekable:
self.start = self.posstack.pop()
if self.level > 0:
self.lastpos = abslastpos - self.start
def is_data(self, line):
return line[:2] != '--'
def section_divider(self, str):
return '--' + str
def end_marker(self, str):
return '--' + str + '--'